/**
 * 创元汇 - WebName
 * https://menger.me
 * @大梦
 */

import React, {Component} from 'react'
import {
    Text,
    View,
    Image,
    ScrollView,
    StyleSheet,
    TouchableOpacity,
    StatusBar,
    TextInput,
    WebView,
    Platform
} from 'react-native'
import { StackActions, NavigationActions } from 'react-navigation';
import NetRequest from '../../utils/utilsRequest'
import ServicesApi from '../../constants/ServicesApi'
import GlobalStyles from '../../constants/GlobalStyles'
import NavigationBar from '../../components/common/NavigationBar'
import UtilsView from '../../utils/utilsView'
import { toastShort, toastLong, consoleLog } from '../../utils/utilsToast'
import {Overlay, Label, Button} from 'teaset';
import AlertManager from '../../components/common/AlertManager'

const WEBVIEW_REF = 'webview';

export default class Renshengou extends Component {

    constructor(props) {
        super(props);
        const { params } = this.props.navigation.state;
        this.state =  {
            user: global.user && global.user.userData ? global.user.userData : '',
            loginState: global.user && global.user.loginState ? global.user.loginState : false,
            fund_id: params.fund_id,
            fundDetailBank: params.fundDetailBank,
            fundDetailBankTitle: params.fundDetailBankTitle,
            fundDetailBankName: params.fundDetailBankName,
            fundDetailBankNum: params.fundDetailBankNum,
            open_day: params.open_day,
            money: '',
            fene: '',
            isTongyi: false,
            money_text: '',
            rate_money: '',
            total_money: '',
            total_money_text: '',
            upup: 0,
            is_first: 2
        }
        // this.netRequest = new NetRequest();
    }

    async componentWillMount(){
        try {
            await this.getInvestData();
        } catch (error) {
            console.log(error);
        }

    }

    componentDidMount(){
        this.willFocus = this.props.navigation.addListener('willFocus', (payload) => {
            this.getUserInfo();
        })
    }

    componentWillUnmount(){
        // console.log(global.user)
        this.willFocus.remove();
        
    }

    onBack = () => {
        this.props.navigation.goBack();
    }

    updateState= (state) => {
        if (!this) { return };
        this.setState(state);
    }

    loadNetData = () => {
               
    }

    getUserInfo = () => {
        let url = ServicesApi.get_member_info;
        let data = {
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        Services.post(url, data, true)
            .then( result => {
                console.log(result.data);
                if (result && result.code == StatusCode.SUCCESS_CODE) {
                    let user = result.data;

                    storage.save({
                        key: 'loginState',
                        data: user
                    });

                    global.user = {
                        loginState: true,
                        userData: user
                    };

                    this.updateState({
                        upup: 1
                    });
                }else{
                    storage.remove({
                        key: 'loginState',
                    });
                    global.user.loginState = false;
                    global.user.userData = [];
                    setTimeout(() => {
                        toastShort('您的账户信息已过期，请重新登录！')
                        const resetAction = NavigationActions.reset({
                            index: 0,
                            actions: [
                                NavigationActions.navigate({ routeName: 'Login'})
                            ]
                        })
                        this.props.navigation.dispatch(resetAction)
                    }, 101)
                }
            })
            .catch( error => {
                toastShort('服务器请求失败，请稍后重试！');
            })
        
    }

    getInvestData = () => {
        let url = ServicesApi.get_investor_info;
        let data = {
            member_id: global.user.userData.id,
            token: global.user.userData.token
        }
        Services.post(url, data, true)
            .then( result => {
                if (result && result.code == StatusCode.SUCCESS_CODE) {
                    console.log('result---->', result);
                    let investor_info = result.data;

                    storage.save({
                        key: 'investInfo',
                        data: investor_info
                    });

                    global.invest = {
                        investInfo: investor_info
                    };
                    this.updateState({
                        upup: 1
                    });
                }else{
                    toastLong(result.msg);
                }
            })
            .catch( error => {
                // console.log(error);
                toastShort('服务器请求失败，请稍后重试！');
            })
    }

    onPushNavigator = (compent) => {
        const { navigate } = this.props.navigation;
        navigate( compent , {
            is_investor: global.user.userData.is_investor,
            fund_id: this.state.fund_id,
            is_first: this.state.is_first,
            fene: this.state.fene,
            money:  this.state.money,
            rate_money: this.state.rate_money,
            total_money: this.state.total_money,
            fund_id: this.state.fund_id,
            fundDetailBankTitle: this.state.fundDetailBankTitle,
            fundDetailBankName: this.state.fundDetailBankName,
            fundDetailBankNum: this.state.fundDetailBankNum,
            open_day: this.state.open_day,
            onCallBack:()=>{
                this.getInvestData();
            }
        })
    }

    pushToSuccess = (compent, order_id) => {
        const { navigate } = this.props.navigation;
        navigate( compent , {
            fene: this.state.fene,
            money:  this.state.money,
            rate_money: this.state.rate_money,
            total_money: this.state.total_money,
            order_id: order_id,
            fund_id: this.state.fund_id,
            fundDetailBankTitle: this.state.fundDetailBankTitle,
            fundDetailBankName: this.state.fundDetailBankName,
            fundDetailBankNum: this.state.fundDetailBankNum,
            open_day: this.state.open_day,
        })
    }

    setTongyi = () => {
        this.setState({
            isTongyi: !this.state.isTongyi,
        })
    }

    setFene = (text) => {
        let url = ServicesApi.get_buy_fund_rate;
        let money = text;
        if(money.indexOf('.')>0 || money.indexOf('。')>0){
            toastLong('申购份额必须是整数，不能包含特殊字符，请重新输入!');
            this.setState({
                fene: '',
                money: '',
                money_text: '',
                rate_money: '',
                total_money: '',
                total_money_text: '',
            })
            return false;
        }
        let data = {
            money: text,
            fund_id: this.state.fund_id
        }
        Services.post(url, data, true)
            .then( result => {
                console.log(result);
                if (result && result.code == StatusCode.SUCCESS_CODE) {
                    console.log(result);
                    this.setState({
                        money_text: result.data.money_text,
                        rate_money: result.data.rate_money,
                        total_money: result.data.total_money,
                        money: result.data.money,
                        total_money_text: result.data.total_money_text,
                    })
                }else{
                    toastLong(result.msg);
                }
            })
            .catch( error => {
                // console.log(error);
                toastShort('服务器请求失败，请稍后重试！');
            })
    }

    submitPre = () => {
        
        let money = this.state.fene;
        if(!money){
            toastShort('请填写申购份额！');
            return false;
        }else if(money.indexOf('.')>0 || money.indexOf('。')>0){
            toastLong('申购份额必须是整数，不能包含特殊字符，请重新输入!');
            this.setState({
                fene: '',
                money: '',
                money_text: '',
                rate_money: '',
                total_money: '',
                total_money_text: '',
            })
            return false;
        }
        if(this.state.is_first == 2){
            toastShort('请选择申购方式');
            return false;
        }else {
            if(global.user.userData.is_pay_auth == 1){
                if(this.state.isTongyi){
                    let url = ServicesApi.apply_buy_fund;
                    let data = {
                        fund_id: this.state.fund_id,
                        money: this.state.fene,
                        order_type: 1,
                        is_first: this.state.is_first,
                        member_id: global.user.userData.id,
                        token: global.user.userData.token,
                    };
                    Services.post(url, data, true)
                        .then( result => {
                            console.log(result);
                            if (result && result.code == StatusCode.SUCCESS_CODE) {
                                if(result.data.style == '004'){
                                    this.Fengxianjieshi(result.data.url, result.data.show_url);
                                }if(result.data.style == '005'){
                                    this.Touzichengnuo(result.data.url, result.data.show_url);
                                }else if(result.data.style == '006'){
                                    this.Hetongwenben6(result.data.id, result.data.url, result.data.show_url)
                                }else if(result.data.style == '007'){
                                    this.Hetongwenben7(result.data.id, result.data.url, result.data.show_url)
                                }
                            }else{
                                toastLong(result.msg);
                            }
                        })
                        .catch( error => {
                            toastShort('服务器请求失败，请稍后重试！');
                        })
                }else{
                    toastShort('请先阅读并同意以上合同协议文件！');
                    return false;
                }
                
            }else{
                toastLong(global.user.userData.is_pay_auth_msg);
            }
        }
    }


    Fengxianjieshi = (ourl, show_link) => {
        let overlayView = (
            <Overlay.PullView side='bottom' modal={false} ref={v => this.overlayView = v}>
                <View style={{backgroundColor: '#fff', width: GlobalStyles.width, height: GlobalStyles.height}}>
                    <WebView
                        startInLoadingState={true}
                        source={{uri: show_link}}
                        style={styles.webContainer}
                    />
                    
                    <View style={styles.botBar}>
                        <TouchableOpacity onPress={()=>{this.overlayView && this.overlayView.close()}} style={[styles.botLeft, ]}>
                            <Text style={[styles.botLeftText, {fontSize: 15}]}>取消</Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.submit004(ourl);}} style={styles.botRight}>
                            <Text style={styles.botRightText}>同意签署并进行下一步</Text>
                        </TouchableOpacity> 
                    </View>
                </View>
            </Overlay.PullView>
        );
        Overlay.show(overlayView);
    }

    submit004 = (ourl) => {
        let url = ServicesApi.create_pdf;
        let data = {
            url: ourl,
            style: '004',
            fund_id: this.state.fund_id,
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        AlertManager.showPopView(<View style={[GlobalStyles.loadingview, GlobalStyles.flexColumnCenter]}><Image source={require('../../assets/images/icons/loading.gif')} style={GlobalStyles.loading} /><Text style={GlobalStyles.loadingtext}>文件生成中，请稍候...</Text></View>, { modal:true })
        Services.post(url, data, true)
        .then( result => {
            console.log(result);
            AlertManager.hide();
            if (result && result.code == StatusCode.SUCCESS_CODE) {
                this.overlayView && this.overlayView.close();
                if(result.data.style == '005'){
                    this.Touzichengnuo(result.data.url, result.data.show_url);
                }else if(result.data.style == '006'){
                    let url = ServicesApi.apply_buy_fund;
                    let data = {
                        fund_id: this.state.fund_id,
                        money: this.state.fene,
                        is_first: this.state.is_first,
                        member_id: global.user.userData.id,
                        token: global.user.userData.token,
                    };
                    Services.post(url, data, true)
                        .then( result => {
                            console.log(result);
                            if (result && result.code == StatusCode.SUCCESS_CODE) {
                                this.Hetongwenben6(result.data.id, result.data.url, result.data.show_url)
                            }else{
                                toastLong(result.msg);
                            }
                        })
                        .catch( error => {
                            toastShort('服务器请求失败，请稍后重试！');
                        })
                }
            }else{
                toastLong(result.msg);
            }
        })
        .catch( error => {
            // toastShort('服务器请求失败，请稍后重试！');
        })
    }


    Touzichengnuo = (ourl, show_link) => {
        let overlayView1 = (
            <Overlay.PullView side='bottom' modal={false} ref={v => this.overlayView1 = v}>
                <View style={{backgroundColor: '#fff', width: GlobalStyles.width, height: GlobalStyles.height}}>
                    <WebView
                        startInLoadingState={true}
                        source={{uri: show_link}}
                        style={styles.webContainer}
                    />
                    
                    <View style={styles.botBar}>
                        <TouchableOpacity onPress={()=>{this.overlayView1 && this.overlayView1.close()}} style={[styles.botLeft, ]}>
                            <Text style={[styles.botLeftText, {fontSize: 15}]}>取消</Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{ this.submit005(ourl);}} style={styles.botRight}>
                            <Text style={styles.botRightText}>同意签署并进行下一步</Text>
                        </TouchableOpacity> 
                    </View>
                </View>
            </Overlay.PullView>
        );
        Overlay.show(overlayView1);
    }

    submit005 = (ourl) => {
        let url = ServicesApi.create_pdf;
        let data = {
            url: ourl,
            style: '005',
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        AlertManager.showPopView(<View style={[GlobalStyles.loadingview, GlobalStyles.flexColumnCenter]}><Image source={require('../../assets/images/icons/loading.gif')} style={GlobalStyles.loading} /><Text style={GlobalStyles.loadingtext}>文件生成中，请稍候...</Text></View>, { modal:true })
        Services.post(url, data, true)
        .then( result => {
            console.log(result);
            AlertManager.hide();
            if (result && result.code == StatusCode.SUCCESS_CODE) {
                this.overlayView1 && this.overlayView1.close()
                if(global.user.userData.new_status >= 8){
                    
                    let url = ServicesApi.apply_buy_fund;
                    let data = {
                        fund_id: this.state.fund_id,
                        money: this.state.fene,
                        is_first: this.state.is_first,
                        member_id: global.user.userData.id,
                        token: global.user.userData.token,
                    };
                    Services.post(url, data, true)
                        .then( result => {
                            console.log(result);
                            if (result && result.code == StatusCode.SUCCESS_CODE) {
                                this.Hetongwenben6(result.data.id, result.data.url, result.data.show_url)
                            }else{
                                toastLong(result.msg);
                            }
                        })
                        .catch( error => {
                            toastShort('服务器请求失败，请稍后重试！');
                        })
                }else {
                    this.onPushNavigator('Shuishou');
                }
            }else{
                toastLong(result.msg);
            }
        })
        .catch( error => {
            // toastShort('服务器请求失败，请稍后重试！');
        })
    }


    Hetongwenben6 = (oid, ourl, show_link) => {
        toastShort('因托管人系统权限问题，其基金合同签章需线下加盖，特此提示。', 3000)
        let overlayView3 = (
            <Overlay.PullView side='bottom' modal={false} ref={v => this.overlayView3 = v}>
                <View style={{backgroundColor: '#fff', width: GlobalStyles.width, height: GlobalStyles.height}}>
                    <WebView
                        ref={(webView) => {this.webview = webView}}
                        startInLoadingState={true}
                        source={{uri: show_link}}
                        style={styles.webContainer}
                    />

                    <View style={styles.hetongico}>
                        <TouchableOpacity onPress={()=>{this.fanhuidingbu()}} style={styles.fanhuidingbu}>
                            <Image source={require('../../assets/images/icons/fanhuidingbu.png')} style={styles.fanhuidingbuico} />
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.yijiandaodi()}} style={styles.yijiandaodi}>
                            <Image source={require('../../assets/images/icons/yijiandaodi.png')} style={styles.yijiandaodiico} />
                        </TouchableOpacity>
                    </View>
                    
                    <View style={styles.botBar}>
                        <TouchableOpacity onPress={()=>{this.overlayView3 && this.overlayView3.close()}} style={[styles.botLeft, ]}>
                            <Text style={[styles.botLeftText, {fontSize: 15}]}>取消</Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.submit006(oid, ourl);}} style={styles.botRight}>
                            <Text style={styles.botRightText}>同意并提交</Text>
                        </TouchableOpacity> 
                    </View>
                </View>
            </Overlay.PullView>
        );
        Overlay.show(overlayView3);
    }

    fanhuidingbu = () => {
        let message = 'fanhuidingbu'
        this.webview.postMessage(message);
    }

    yijiandaodi = () => {
        let message = 'yijiandaodi'
        this.webview.postMessage(message);
    }


    Hetongwenben7 = (oid, ourl, show_link) => {
        toastShort('因托管人系统权限问题，其基金合同签章需线下加盖，特此提示。', 3000)
        let overlayView3 = (
            <Overlay.PullView side='bottom' modal={false} ref={v => this.overlayView3 = v}>
                <View style={{backgroundColor: '#fff', width: GlobalStyles.width, height: GlobalStyles.height}}>
                    <WebView
                        ref={(webView) => {this.webview = webView}}
                        startInLoadingState={true}
                        source={{uri: show_link}}
                        style={styles.webContainer}
                    />

                    <View style={[styles.hetongico, GlobalStyles.hide]}>
                        <TouchableOpacity onPress={()=>{this.fanhuidingbu()}} style={styles.fanhuidingbu}>
                            <Image source={require('../../assets/images/icons/fanhuidingbu.png')} style={styles.fanhuidingbuico} />
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.yijiandaodi()}} style={styles.yijiandaodi}>
                            <Image source={require('../../assets/images/icons/yijiandaodi.png')} style={styles.yijiandaodiico} />
                        </TouchableOpacity>
                    </View>
                    
                    <View style={styles.botBar}>
                        <TouchableOpacity onPress={()=>{this.overlayView3 && this.overlayView3.close()}} style={[styles.botLeft, ]}>
                            <Text style={[styles.botLeftText, {fontSize: 15}]}>取消</Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.submit007(oid, ourl);}} style={styles.botRight}>
                            <Text style={styles.botRightText}>同意并提交</Text>
                        </TouchableOpacity> 
                    </View>
                </View>
            </Overlay.PullView>
        );
        Overlay.show(overlayView3);
    }

    submit006 = (oid, ourl) => {
        let url = ServicesApi.create_pdf;
        let data = {
            url: ourl,
            style: '006',
            order_id: oid,
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        AlertManager.showPopView(<View style={[GlobalStyles.loadingview, GlobalStyles.flexColumnCenter]}><Image source={require('../../assets/images/icons/loading.gif')} style={GlobalStyles.loading} /><Text style={GlobalStyles.loadingtext}>文件生成中，请稍候...</Text></View>, { modal:true })
        Services.post(url, data, true)
        .then( result => {
            console.log(result);
            AlertManager.hide();
            if (result && result.code == StatusCode.SUCCESS_CODE) {
                this.overlayView3 && this.overlayView3.close()
                this.pushToSuccess('Tijiaochenggong', oid);
            }else{
                toastLong(result.msg);
            }
        })
        .catch( error => {
            // toastShort('服务器请求失败，请稍后重试！');
        })
    }

    submit007 = (oid, ourl) => {
        let url = ServicesApi.create_pdf;
        let data = {
            url: ourl,
            style: '007',
            order_id: oid,
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        AlertManager.showPopView(<View style={[GlobalStyles.loadingview, GlobalStyles.flexColumnCenter]}><Image source={require('../../assets/images/icons/loading.gif')} style={GlobalStyles.loading} /><Text style={GlobalStyles.loadingtext}>文件生成中，请稍候...</Text></View>, { modal:true })
        Services.post(url, data, true)
        .then( result => {
            console.log(result);
            AlertManager.hide();
            if (result && result.code == StatusCode.SUCCESS_CODE) {
                this.overlayView3 && this.overlayView3.close()
                this.pushToSuccess('Tijiaochenggong', oid);
            }else{
                toastLong(result.msg);
            }
        })
        .catch( error => {
            // toastShort('服务器请求失败，请稍后重试！');
        })
    }
    

    // submit = () => {
    //     let url = ServicesApi.apply_buy_fund;
    //     let data = {
    //         fund_id: this.state.fund_id,
    //         money: this.state.fene,
    //         is_first: this.state.is_first,
    //         member_id: global.user.userData.id,
    //         token: global.user.userData.token,
    //     };
    //     Services.post(url, data, true)
    //         .then( result => {
    //             console.log(result);
    //             if (result && result.code == StatusCode.SUCCESS_CODE) {
    //                 if(result.data.style == '006'){
    //                     this.Hetongwenben6(result.data.id, result.data.url);
    //                 }else if(result.data.style == '007'){
    //                     this.Hetongwenben7(result.data.id, result.data.url);
    //                 }
    //             }else{
    //                 toastShort(result.msg);
    //             }
    //         })
    //         .catch( error => {
    //             toastShort('服务器请求失败，请稍后重试！');
    //         })
    //     // toastShort('提交成功');
    //     // this.pushToSuccess('Tijiaochenggong', shuju);
    // }

    render(){
        let navigationBar = {
            backgroundColor: '#fff',
            borderBottomColor: '#f2f2f2',
            borderBottomWidth: 1
        }
        return (
            <View style={styles.container}>
                <NavigationBar
                    title = {'认申购'}
                    style = {navigationBar}
                    titleStyle = {{color: '#333333'}}
                    leftButton = {UtilsView.getLeftBlackButton(() => this.onBack())}
                    rightButton = {UtilsView.getRightKefuBlackButton(() => this.onPushNavigator('Kefu'))}
                />
                <StatusBar
                    animated = {true}
                    hidden = {false}
                    backgroundColor = {'transparent'}
                    translucent = {true}
                    barStyle = {'dark-content'}
                />
                <ScrollView keyboardShouldPersistTaps={'handled'}>
                    <View style={[GlobalStyles.whiteModule, {padding: 15,}]}>
                        <Text style={styles.tishi}>提示：按照监管部门规定，购买私募基金前请您先进行以下操作：</Text>
                        <View style={styles.pingguItem}>
                            {this.pinggu()}
                            {this.invest()}
                            {this.yinhangka()}
                        </View>                            
                    </View>

                    <View style={[GlobalStyles.whiteModule, {padding: 15 }]}>
                        <Text style={[styles.tishi, {fontSize: 14, marginBottom: 10}]}>请选择申购方式</Text>
                        <View style={[styles.shifouWrap, GlobalStyles.flexRowBetween, {marginBottom: 15}]}>
                            {this.state.is_first == 1 ?
                                <TouchableOpacity onPress={()=>{this.updateState({is_first: 1})}} style={[styles.shifou, styles.shifouActive, {marginRight: 10}]}>
                                    <Text style={[styles.shifouText, styles.shifouTextActive]}>首投</Text>
                                </TouchableOpacity>
                                :
                                <TouchableOpacity onPress={()=>{this.updateState({is_first: 1})}} style={[styles.shifou, {marginRight: 10}]}>
                                    <Text style={[styles.shifouText]}>首投</Text>
                                </TouchableOpacity>
                            }
                            {this.state.is_first == 0 ?
                                <TouchableOpacity onPress={()=>{this.updateState({is_first: 0})}} style={[styles.shifou, styles.shifouActive,]}>
                                    <Text style={[styles.shifouText, styles.shifouTextActive]}>追投</Text>
                                </TouchableOpacity>
                                :
                                <TouchableOpacity onPress={()=>{this.updateState({is_first: 0})}} style={styles.shifou}>
                                    <Text style={styles.shifouText}>追投</Text>
                                </TouchableOpacity>
                            }
                        </View>
                        <View style={styles.shengoujia}>
                            <View style={styles.shengoufene}>
                                <TextInput
                                    placeholder={'请填写申购份额'}
                                    keyboardType="numeric"
                                    onChangeText={(text) => {
                                        this.setState({
                                            fene: text
                                        })
                                        this.setFene(text);
                                    }}
                                    style={[styles.cellInput, GlobalStyles.isIOS ? null : styles.inputAndroid]} 
                                    underlineColorAndroid={'transparent'}
                                    value={this.state.fene}
                                >
                                </TextInput>
                            </View>
                            <View style={[styles.zongjine, GlobalStyles.flexRowBetween]}>
                                <Text style={styles.jinefuhao}>￥</Text>
                                <Text style={styles.jineshuzhi}>{this.state.total_money}</Text>
                            </View>
                            <View style={[styles.jinebaokuo, GlobalStyles.flexRowBetween]}>
                                <Text style={styles.jinebkleft}>包括：</Text>
                                <View style={styles.jinebkright}>
                                    <Text style={styles.jinebkrightline}>人民币：{this.state.total_money_text}</Text>
                                    <Text style={styles.jinebkrightline}>认申购价款：{this.state.money}</Text>
                                    <Text style={styles.jinebkrightline}>认申购费用：{this.state.rate_money}</Text>
                                </View>
                            </View>
                        </View>

                        <View style={[GlobalStyles.radioItem, GlobalStyles.flexRowStartStart, {marginTop: 20}]}>
                            {this.state.isTongyi ?
                                <TouchableOpacity onPress={() => {this.setTongyi()}} style={[GlobalStyles.checkboxLeft, {borderColor: GlobalStyles.themeColor, backgroundColor: GlobalStyles.themeColor}]}>
                                    <Image source={require('../../assets/images/icons/icon_gouxuan.png')} style={[GlobalStyles.gouxuanIco]} />
                                </TouchableOpacity>
                            : 
                                <TouchableOpacity onPress={() => {this.setTongyi()}} style={[GlobalStyles.checkboxLeft, {borderColor: '#666', }]}></TouchableOpacity> 
                            }
                            <TouchableOpacity onPress={() => {this.onPushNavigator('JijinHetong')}} style={[styles.tongyiright]}>
                                <Text style={styles.orderText}>我已阅读
                                <Text style={[styles.orderText,  styles.xiahuaxian, {color: GlobalStyles.themeColor}]}>基金合同、投资者承诺书、投资告知书、申购提示书、赎回提示书等，</Text>
                                清楚并认可上述文件告知内容，并愿意自行承担由此可能导致的一切风险和损失。</Text>
                            </TouchableOpacity>
                        </View>

                        <View style={styles.zhanghu}>
                            <Text style={[styles.orderText, {marginBottom: 8}]}>订单提交后，请于{this.state.open_day}下午15点前，使用绑定的银行卡（尾号{global.user.userData.bank_num}）将合计金额汇款至募集账户——</Text>
                            <Text style={[styles.orderText, styles.textWeight, {color: GlobalStyles.themeColor}]}>银行户名：{this.state.fundDetailBankTitle}</Text>
                            <Text style={[styles.orderText, styles.textWeight, {color: GlobalStyles.themeColor}]}>开户行：{this.state.fundDetailBankName}</Text>
                            <Text style={[styles.orderText, styles.textWeight, {color: GlobalStyles.themeColor}]}>银行账号：{this.state.fundDetailBankNum}</Text>
                        </View>
                    </View>

                </ScrollView>
                    
                <View style={styles.botBar}>
                    <TouchableOpacity onPress={()=>{this.onPushNavigator('Jisuanqi')}} style={styles.botLeft}>
                        <Image source={require('../../assets/images/icons/icon_shouyi.png')} style={[styles.botLeftIco, {width: 24*96/100}]} />
                        <Text style={styles.botLeftText}>收益计算</Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={()=>{this.submitPre()}} style={styles.botRight}>
                        <Text style={styles.botRightText}>提交</Text>
                    </TouchableOpacity> 
                </View>
            </View>
        );
    }

    invest = () => {
        // console.log(global.user.userData.is_investor);
        if(global.user.userData.is_investor == -2){
            global.invest.investInfo.editable = true;
            return (
                <TouchableOpacity onPress={() => {this.onPushNavigator('RenzhengType');toastShort(global.user.userData.back_msg)}} style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>专业投资者认证</Text>
                        <Text style={[styles.userlistRightText, {color: '#f00'}]}>{global.user.userData.investor_msg}</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </TouchableOpacity>
            )
        }else if(global.user.userData.is_investor == -1){
            global.invest.investInfo.editable = true;
            return (
                <TouchableOpacity onPress={() => {this.onPushNavigator('RenzhengType',global.user.userData.back_msg)}} style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>专业投资者认证</Text>
                        <Text style={[styles.userlistRightText, {color: '#f00'}]}>{global.user.userData.investor_msg}</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </TouchableOpacity>
            )
        }else if(global.user.userData.is_investor == 0){
            global.invest.investInfo.editable = true;
            return (
                <TouchableOpacity onPress={() => {this.onPushNavigator('RenzhengType')}} style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>专业投资者认证</Text>
                        <Text style={styles.userlistRightText}>{global.user.userData.investor_msg}</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </TouchableOpacity>
            )
        }else if(global.user.userData.is_investor == 1){
            global.invest.investInfo.editable = false;
            return (
                <TouchableOpacity onPress={() => {this.onPushNavigator('Renzheng');toastShort(global.user.userData.back_msg)}} style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>专业投资者认证</Text>
                            <Text style={styles.userlistRightText}>{global.user.userData.investor_msg}</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </TouchableOpacity>
            )
        }else if(global.user.userData.is_investor == 2){
            global.invest.investInfo.editable = false;
            return (
                <TouchableOpacity onPress={() => {this.onPushNavigator('Renzheng');toastShort(global.user.userData.back_msg)}} style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>专业投资者认证</Text>
                            <Text style={[styles.userlistRightText, {color: '#f00'}]}>{global.user.userData.investor_msg}</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </TouchableOpacity>
            )
        }            
            
    }

    yinhangka = () => {
        if(global.user.userData.is_pay_auth == -1){
            if(global.user.userData.is_investor == 0){
                return (
                    <TouchableOpacity onPress={() => {toastShort(global.user.userData.is_pay_auth_msg);this.onPushNavigator('RenzhengType')}} style={[GlobalStyles.userlist, styles.pingguList]}>
                        <View style={GlobalStyles.userlistright}>
                            <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>绑定银行借记卡</Text>
                            <Text style={styles.userlistRightText}>{global.user.userData.is_bank_card == 1 ? '已绑定' : '未绑定'}</Text>
                            <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                        </View>
                    </TouchableOpacity>
                )
            }else{
                return (
                    <TouchableOpacity onPress={() => {toastShort(global.user.userData.is_pay_auth_msg);}} style={[GlobalStyles.userlist, styles.pingguList]}>
                        <View style={GlobalStyles.userlistright}>
                            <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>绑定银行借记卡</Text>
                            <Text style={styles.userlistRightText}>{global.user.userData.is_bank_card == 1 ? '已绑定' : '未绑定'}</Text>
                            <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                        </View>
                    </TouchableOpacity>
                )
            }
        }else{
            return (
                <TouchableOpacity onPress={() => {this.onPushNavigator('Yinhangka')}} style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>绑定银行借记卡</Text>
                        <Text style={styles.userlistRightText}>{global.user.userData.is_bank_card == 1 ? '已绑定' : '未绑定'}</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </TouchableOpacity>
            )
        }
    }

    pinggu = () => {
        console.log('global.user.userData---->', global.user.userData);
        if(global.user.userData.is_risk == 1){
            return (
                <View style={[GlobalStyles.userlist, styles.pingguList]}>
                    <View style={GlobalStyles.userlistright}>
                        <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>风险承受能力评估</Text>
                        <Text style={styles.userlistRightText}>已通过</Text>
                        <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                    </View>
                </View>
            )
        }else if(global.user.userData.is_risk == 0) {
            if(global.user.userData.is_risk_answer == 0){
                return (
                    <TouchableOpacity onPress={() => {this.onPushNavigator('Pinggu')}} style={[GlobalStyles.userlist, styles.pingguList]}>
                        <View style={GlobalStyles.userlistright}>
                            <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>风险承受能力评估</Text>
                            <Text style={styles.userlistRightText}>未评估</Text>
                            <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                        </View>
                    </TouchableOpacity>
                )  
            }else{
                if(global.user.userData.new_status == 0){
                    return (
                        <TouchableOpacity onPress={()=>{this._onPressAlert2()}} style={[GlobalStyles.userlist, styles.pingguList]}>
                            <View style={GlobalStyles.userlistright}>
                                <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>风险承受能力评估</Text>
                                <Text style={styles.userlistRightText}>待签署</Text>
                                <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                            </View>
                        </TouchableOpacity>
                    ) 
                }else if(global.user.userData.new_status == 1){
                    return (
                        <TouchableOpacity onPress={()=>{this._onPressAlert3()}} style={[GlobalStyles.userlist, styles.pingguList]}>
                            <View style={GlobalStyles.userlistright}>
                                <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>风险承受能力评估</Text>
                                <Text style={styles.userlistRightText}>待签署</Text>
                                <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                            </View>
                        </TouchableOpacity>
                    )
                }else if(global.user.userData.new_status == 2){
                    return (
                        <TouchableOpacity onPress={()=>{this._onPressAlert4()}} style={[GlobalStyles.userlist, styles.pingguList]}>
                            <View style={GlobalStyles.userlistright}>
                                <Text style={[GlobalStyles.userlisttext, styles.renzhengText]}>风险承受能力评估</Text>
                                <Text style={styles.userlistRightText}>待签署</Text>
                                <Image source={require('../../assets/images/icons/icon_user_arrow.png')} style={GlobalStyles.userlistmore} />
                            </View>
                        </TouchableOpacity>
                    )
                }
            }
        }
    }


}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: GlobalStyles.bgColor,
    },
    webContainer: {
        width: GlobalStyles.width,
        height: GlobalStyles.height,
        flex: 1,
        backgroundColor: '#fff',
        marginTop: Platform.OS === 'ios' ? -15 : 0,
    },
    userlistRightText: {
        position: 'absolute',
        right: 20,
        color: '#585858',
    },
    textWeight: {
        fontWeight: 'bold'
    },
    xiahuaxian: {
        textDecorationLine: 'underline'
        // borderBottomWidth: 1,
        // borderBottomColor: GlobalStyles.themeColor
    },
    tishi: {
        color: GlobalStyles.themeColor,
        fontSize: 11.5,
        marginBottom: 5,
        fontWeight: 'bold'
    },
    pingguItem: {

    },
    pingguList: {
        borderWidth: 1,
        borderColor: '#f2f2f2',
        marginTop: 10,
        borderRadius: 5
    },
    renzhengText: {
        color: GlobalStyles.themeColor,
        fontWeight: 'bold'
    },
    botBar: {
        height: 54,
        backgroundColor: '#fff',
        display: 'flex',
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        borderTopColor: '#ececec',
        borderTopWidth: 1,

    },
    botLeft: {
        height: 54,
        flex: 1,
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center'
    },
    botLeftIco: {
        height: 24,

    },
    botLeftText: {
        fontSize: 13,
        color: '#666',
        height: 20,
        lineHeight: 20,
    },
    botRight: {
        flex: 2.5,
        backgroundColor: GlobalStyles.themeColor,
        height: 54,
        justifyContent: 'center',
        alignItems: 'center',

    },
    botRightText: {
        color: '#fff',
        fontSize: 18,
        fontWeight: 'bold'
    },
    shengoujia: {
        backgroundColor: GlobalStyles.themeColor,
        borderRadius: 8,

    },
    shengoufene: {

    },
    cellInput:{
        width: GlobalStyles.width - 50,
        height: 45,
        marginLeft: 10,
        fontSize:15,
        textAlign:'center',
        color: GlobalStyles.themeColor,
        backgroundColor: '#fff',
        borderRadius: 5,
        marginTop: 10,
        
    },
    inputAndroid:{
        padding: 0,
    },
    zongjine: {
        marginLeft: 15,
        marginRight: 15,
        paddingTop: 12,
        paddingBottom: 12,
        borderBottomColor: 'rgba(255, 255, 255, 0.2)',
        borderBottomWidth: 1
    },
    jinefuhao: {
        color: '#fff',
        fontSize: 16,
        fontWeight: 'bold'
    },
    jineshuzhi: {
        color: '#fff',
        fontSize: 16,
        fontWeight: 'bold'
    },
    jinebaokuo: {
        padding: 15,
    },
    jinebkleft: {
        color: '#fff',
    },
    jinebkright: {

    },
    jinebkrightline: {
        color: '#fff',
        fontSize: 13,
        lineHeight: 18
    },
    tongyi: {
        marginTop: 15,
        width: GlobalStyles.width - 30,
        height: 60,
    },
    tongyileft: {
        width: 18,
        marginRight: 6,
        height: 60,
    },
    tongyikuang: {
        width: 18,
        height: 18,
        borderWidth: 1.5,
        borderColor: '#ececec',
        borderRadius: 4,
        marginTop: 2,
    },
    tongyidagou: {
        display: 'none',
    },
    tongyiright: {
        flex: 1,
    },
    orderText: {
        fontSize: 12.5,
        color: '#666',
        lineHeight: 20
    },
    zhanghu: {
        marginTop: 20
    },
    shifouWrap: {
        width: GlobalStyles.width - 30
    },
    shifou: {
        // width: (GlobalStyles.width - 30)/2,
        height: 45,
        borderWidth: 1,
        borderColor: GlobalStyles.themeColor,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flex: 1,
        // backgroundColor: '#f00'
    },
    shifouText: {
        textAlign: 'center',
        fontSize: 16,
        color: GlobalStyles.themeColor,
    },
    shifouActive: {
        backgroundColor: GlobalStyles.themeColor,
    },
    shifouTextActive: {
        color: '#fff',
        
    },
    hetongico: {
        backgroundColor: 'transparent',
        position: 'absolute',
        bottom: 80,
        right: 15
    },
    fanhuidingbu: {
        backgroundColor: 'transparent',
        marginBottom: 10,
    },
    fanhuidingbuico: {
        backgroundColor: 'transparent',
        width: 40,
        height: 40,
    },
    yijiandaodi: {
        backgroundColor: 'transparent',

    },
    yijiandaodiico: {
        backgroundColor: 'transparent',
        width: 40,
        height: 40,
    },
});
